Skip to content

Implement sass --embedded in pure JS mode #2413

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 23 commits into
base: main
Choose a base branch
from

Conversation

ntkme
Copy link
Contributor

@ntkme ntkme commented Oct 26, 2024

Closes #2325.

sass/embedded-host-node#344

Implementation

The actual isolate dispatcher and compilation dispatcher are nearly unchanged. However, I had to replace isolate with worker communication, and mock tons of small things that do not work on node.

Testing

  • All Dart embedded tests are passing. - GitHub CI has been updated to run these in this PR.
  • All JS API tests are passing. - GitHub CI has been updated to run these in this PR.
  • All Ruby API tests are passing.

@ntkme ntkme force-pushed the embedded-compiler branch from 8d7d4de to 7084da7 Compare October 26, 2024 02:31
@ntkme ntkme marked this pull request as ready for review October 26, 2024 02:50
@ntkme ntkme marked this pull request as draft October 26, 2024 03:40
@ntkme ntkme force-pushed the embedded-compiler branch 2 times, most recently from e66df5b to d53fcc5 Compare October 26, 2024 17:27
@ntkme ntkme force-pushed the embedded-compiler branch 9 times, most recently from d7e6206 to b3794eb Compare October 28, 2024 06:35
@ntkme ntkme marked this pull request as ready for review October 28, 2024 06:49
@ntkme ntkme force-pushed the embedded-compiler branch 3 times, most recently from 9112b44 to 54fabf3 Compare October 28, 2024 07:42
@ntkme ntkme force-pushed the embedded-compiler branch 8 times, most recently from 257b4fd to ac718ee Compare October 28, 2024 21:03
Copy link
Contributor

@nex3 nex3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Finally managed to carve out some time for this. I haven't done a complete review yet, but this should be enough to get you started.

Comment on lines +199 to +213
if (_gracefulShutdown) {
_channel.sink.close();
} else {
exit(exitCode);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is also changing the current behavior for the Dart VM.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually it's not changing any behavior for end users, see #2413 (comment)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The VM was previously calling _channel.sink.close() here. Since _gracefulShutdown is only needed to work around issues with Node.js, does this code need to change at all? Or could we just have the VM gracefully shut down even though it doesn't strictly need to, just to remove some extra complexity?

Either way, it's worth documenting those Node.js issues in the code itself so we know what to work around when making changes in the future.

@ntkme ntkme force-pushed the embedded-compiler branch from acfc9cf to 7063dd2 Compare April 2, 2025 23:39
@ntkme ntkme force-pushed the embedded-compiler branch from cf348da to 7857415 Compare April 3, 2025 00:17
@ntkme ntkme force-pushed the embedded-compiler branch from 1978cd2 to 197eb0f Compare April 3, 2025 00:58
Copy link
Contributor

@nex3 nex3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another partial review, but I think we're making good progress!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can also just go in the existing io catch-all.

Comment on lines +199 to +213
if (_gracefulShutdown) {
_channel.sink.close();
} else {
exit(exitCode);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The VM was previously calling _channel.sink.close() here. Since _gracefulShutdown is only needed to work around issues with Node.js, does this code need to change at all? Or could we just have the VM gracefully shut down even though it doesn't strictly need to, just to remove some extra complexity?

Either way, it's worth documenting those Node.js issues in the code itself so we know what to work around when making changes in the future.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be part of the existing IO library (which already has definitions for exitCode).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, I was trying to implement this with new js interop from dart 3.3 without relying on the node_interop package which heavily depends on deprecated dart:js_util, which will start to break at some point.

For exitCode I can use the existing one we have.

What about Stdin, Stdout, Stderr? These are effectively wrapper classes on node stdio to create an interface that's same as the dart built-in classes while it only partially implement necessarily methods we need on those interface. @nex3 What's your preference here? Create another interface that wraps the original dart interface?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any work to expose existing JS APIs should go in lib/src/js.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, this is a saparate file because it's new js interop from dart 3.3, which I found a bit awkward to put it together with the classic interop code in the same place. Any recommendation on how to deal with it?

@ntkme
Copy link
Contributor Author

ntkme commented Apr 8, 2025

Applied most of the feedbacks. However, I have a awkward feeling about mixing classic js interop and new js interop in the same file, which is why I have lots of js specific things with new interop are only in embedded folder instead of in the generic folder.

@nex3 I haven't changed these yet, as I want to hear what's your thought on this.

@ntkme
Copy link
Contributor Author

ntkme commented Apr 8, 2025

Another note: The reason I tried to avoid classic interop and node_introp is that I couldn't get channel.port2 passed to Worker() constructor correctly with node_interop. Neither allowInterop() nor explicit casting worked, and it was a nightmare trying to debug what went wrong. I looked at node_interop repo trying to see if there is any example for it and there is no actual usage of transferList anywhere.

The new dart 3.3 js interop on the other hands was way more straight forward to use and debug. I got Worker() working on my first attempt.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement sass --embedded in pure JS mode
3 participants